% Compute Confidence interval of an interval estimator.
% Stoye(2009) page 1305.

function CI=stoye2009(theta_l, theta_u, sigma_l_sq,sigma_u_sq,covariance,SampleSize)
    
    global delta sigma_l sigma_u SampleSize
    delta=theta_u - theta_l;
    sigma_l=sqrt(sigma_l_sq); sigma_u=sqrt(sigma_u_sq);
    rho=covariance/(sigma_l * sigma_u);

    
    % Constraint Optimization: Equations (4) and (5).
    options=optimset('Display','off');
    c=fmincon(@objfun,[0,0],[],[],[],[],[],[],@nonlcon,options);

    
    % Construct a confidence interval.
    CI=[theta_l-(sigma_l*c(1)/sqrt(SampleSize)), theta_u+(sigma_u*c(2)/sqrt(SampleSize))];
    
end